package com.seari.service.Impl;

import com.seari.bean.*;
import com.seari.utils.GuavaCacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.seari.mapper.EmergencyResourceMapper;
import com.seari.pojo.QueueContent;
import com.seari.service.EmergencyResourcesService;

import java.util.List;

@Service("emergencyResourcesService")
public class EmergencyResourcesServiceImpl implements EmergencyResourcesService{
	
	@Autowired
	public EmergencyResourceMapper emergencyResourceMapper;

	@Override
	public FaultNum getEmergencyResources() {

		return emergencyResourceMapper.getEmergencyResources();

	}

	@Override
	@DS("slave_1")
	public List<EmergencyEquipment> getEmergencyEquipment() {
		
		List<EmergencyEquipment> lists = emergencyResourceMapper.getEmergencyEquipment();
		List<StationPosition> stationPositionLists = (List<StationPosition>) GuavaCacheUtil.get("stationPositionList");
		
//		for (EmergencyEquipment list:lists) {
//			for (StationPosition stationPosition:stationPositionLists) {
//				if (stationPosition.getName().contains(list.getDeviceAddress())){
//					Position GPS = new Position();
//					GPS.setXaxis(stationPosition.getXaxis());
//					GPS.setYaxis(stationPosition.getYaxis());
//					list.setGPS(GPS);
//				}
//			}
//		}
		return lists;
	}

	@Override
	@DS("slave_1")
	public List<EmergencyTeam> getEmergencyTeam() {
		
		List<EmergencyTeam> lists = emergencyResourceMapper.getEmergencyTeam();
		
		for(EmergencyTeam emergencyTeam:lists) {
			emergencyTeam.setQueueContent(QueueContent.queueMap.get(emergencyTeam.getQueueContent()));
		}
		
//		List<String> queueIdList = emergencyResourceMapper.getQueueId(faultId);
//		List<StationPosition> stationPositionLists = (List<StationPosition>) GuavaCacheUtil.get("stationPositionList");
//		
//		for (EmergencyTeam team:lists) {
//			team.setType("2");
//			for (String str :queueIdList) {
//				if(team.getQueueId().equals(str)){
//					team.setType("1");
//				}
//			}
//		}
//
//		for (EmergencyTeam team:lists) {
//			for (StationPosition stationPosition:stationPositionLists) {
//				if (stationPosition.getName().contains(team.getQueueAddressname())){
//					Position GPS = new Position();
//					GPS.setXaxis(stationPosition.getXaxis());
//					GPS.setYaxis(stationPosition.getYaxis());
//					team.setGps(GPS);
//				}
//			}
//		}

		return lists;
	}

	@Override
	@DS("slave_1")
	public List<ServiceCompany> getGzZyList() {

		List<ServiceCompany> lists = emergencyResourceMapper.getGzZyList();

		return lists;
	}
	
	@Override
	@DS("slave_1")
	public List<JqGzFlag> getJqGzFlags(){
		return emergencyResourceMapper.getJqGzFlags();
	}

}
